package com.saya.model;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.saya.utils.Utils;

public class Comment {
	  private String phoneNumber;
	  private String fullname;
	  private String email;
	  private String subject;
	  private String content;
	  private String status;
	  private String commentdate;

	  public String getPhoneNumber()
	  {
	    return this.phoneNumber;
	  }
	  public void setPhoneNumber(String phoneNumber) {
	    this.phoneNumber = phoneNumber;
	  }
	  public String getSubject() {
	    return this.subject;
	  }
	  public void setSubject(String subject) {
	    this.subject = subject;
	  }
	  public String getContent() {
	    return this.content;
	  }
	  public void setContent(String content) {
	    this.content = content;
	  }
	  public String getStatus() {
	    return this.status;
	  }
	  public void setStatus(String status) {
	    this.status = status;
	  }
	  public String getCommentdate() {
	    return this.commentdate;
	  }
	  public void setCommentdate(String commentdate) {
	    this.commentdate = commentdate;
	  }
	  public String getFullname() {
	    return this.fullname;
	  }
	  public void setFullname(String fullname) {
	    this.fullname = fullname;
	  }

	  public String getEmail() {
	    return this.email;
	  }
	  public void setEmail(String email) {
	    this.email = email;
	  }

	  public static Boolean Create(String phoneNumber, String fullname, String email, String subject, String content) {
	    Entity user = Utils.getEntity("User", phoneNumber);
	    if (user == null) {
	      return Boolean.valueOf(false);
	    }
	    Entity e = new Entity("Comment", user.getKey());
	    e.setProperty("PhoneNumber", phoneNumber);
	    e.setProperty("FullName", fullname);
	    e.setProperty("Email", email);
	    e.setProperty("Subject", subject);
	    e.setProperty("Content", content);
	    e.setProperty("CommentDate", Utils.getCurrentDate());

	    Boolean isSent = Utils.SentEmail(email, fullname, subject, content);
	    if (isSent.booleanValue())
	      e.setProperty("Status", "1");
	    else {
	      e.setProperty("Status", "2");
	    }
	    Key k = Utils.persistEntity(e);
	    if (k != null) {
	      return Boolean.valueOf(true);
	    }
	    return Boolean.valueOf(false);
	  }

}
